{% extends "adminmain.html" %}

{% block title %}存款业务管理{% endblock %}

{% block extra_css %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/admin_main.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/admin_deposit.css') }}">
{% endblock %}

{% block content %}
<div class="dashboard-container">
    <!-- 面包屑导航 -->
    <nav aria-label="breadcrumb" class="mb-4">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="{{ url_for('admin.adminmain') }}">首页</a></li>
            <li class="breadcrumb-item active" aria-current="page">存款业务管理</li>
        </ol>
    </nav>
    
    <!-- 存款业务管理卡片 -->
    <div class="dashboard-card">
        <div class="card-header">
            <h2><i class="bi bi-piggy-bank me-2"></i>存款业务管理</h2>
            <div class="card-actions">
                <button class="btn btn-success" id="addDepositBtn">
                    <i class="bi bi-plus-circle me-1"></i>添加存款类型
                </button>
                <form method="POST" action="{{ url_for('admindeposit.admindeposit') }}" style="display:inline;">
                    <input type="hidden" name="action" value="export_csv">
                    <button type="submit" class="btn btn-primary">
                        <i class="bi bi-file-earmark-arrow-down me-1"></i>导出CSV
                    </button>
                </form>
            </div>
        </div>

        <!-- 搜索区域 -->
        <div class="search-section mb-4">
            <div class="row g-3">
                <div class="col-md-6">
                    <input type="text" class="form-control" placeholder="输入存款类型名称" 
                           id="savingNameSearch" value="{{ savingNameSearch }}">
                </div>
                <div class="col-md-6">
                    <input type="text" class="form-control" placeholder="输入描述信息" 
                           id="descripSearch" value="{{ descripSearch }}">
                </div>
                <div class="col-md-12">
                    <button class="btn btn-primary w-100" id="searchBtn">
                        <i class="bi bi-search me-1"></i>搜索存款类型
                    </button>
                </div>
            </div>
        </div>

        <!-- 存款类型表格 -->
        <div class="table-responsive">
            <table class="data-table">
                <thead>
                    <tr>
                        <th>存款类型ID</th>
                        <th>存款类型名称</th>
                        <th>描述</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for deposit in deposits.items %}
                    <tr>
                        <td>{{ deposit.savingID }}</td>
                        <td>{{ deposit.savingName }}</td>
                        <td>{{ deposit.descrip or '-' }}</td>
                        <td>
                            <button class="btn btn-sm btn-warning edit-btn" 
                                    data-id="{{ deposit.savingID }}"
                                    data-name="{{ deposit.savingName }}"
                                    data-desc="{{ deposit.descrip }}">
                                <i class="bi bi-pencil"></i> 编辑
                            </button>
                            <button class="btn btn-sm btn-danger delete-btn" 
                                    data-id="{{ deposit.savingID }}"
                                    data-name="{{ deposit.savingName }}">
                                <i class="bi bi-trash"></i> 删除
                            </button>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>

        <!-- 分页控件 -->
        <nav class="mt-4">
            <ul class="pagination justify-content-center">
                {% if deposits.has_prev %}
                <li class="page-item">
                    <a class="page-link" href="{{ url_for('admindeposit.admindeposit', 
                        page=deposits.prev_num, 
                        savingNameSearch=savingNameSearch, 
                        descripSearch=descripSearch) }}">上一页</a>
                </li>
                {% else %}
                <li class="page-item disabled">
                    <a class="page-link" href="#">上一页</a>
                </li>
                {% endif %}

                {% for page_num in deposits.iter_pages() %}
                    {% if page_num %}
                        <li class="page-item {% if page_num == deposits.page %}active{% endif %}">
                            <a class="page-link" href="{{ url_for('admindeposit.admindeposit', 
                                page=page_num, 
                                savingNameSearch=savingNameSearch, 
                                descripSearch=descripSearch) }}">{{ page_num }}</a>
                        </li>
                    {% else %}
                        <li class="page-item disabled"><span class="page-link">...</span></li>
                    {% endif %}
                {% endfor %}

                {% if deposits.has_next %}
                <li class="page-item">
                    <a class="page-link" href="{{ url_for('admindeposit.admindeposit', 
                        page=deposits.next_num, 
                        savingNameSearch=savingNameSearch, 
                        descripSearch=descripSearch) }}">下一页</a>
                </li>
                {% else %}
                <li class="page-item disabled">
                    <a class="page-link" href="#">下一页</a>
                </li>
                {% endif %}
            </ul>
        </nav>
    </div>
</div>

<!-- 存款类型模态框 (添加/编辑) -->
<div class="modal fade" id="depositModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="modalTitle">添加存款类型</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <form method="POST" action="{{ url_for('admindeposit.admindeposit') }}">
                <div class="modal-body">
                    <input type="hidden" name="action" id="formAction" value="add">
                    <input type="hidden" name="savingID" id="savingID">
                    <div class="mb-3">
                        <label class="form-label">存款类型名称 <span class="text-danger">*</span></label>
                        <input type="text" class="form-control" id="savingName" name="savingName" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">描述信息</label>
                        <textarea class="form-control" id="descrip" name="descrip" rows="3"></textarea>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- 删除确认模态框 -->
<div class="modal fade" id="deleteModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">确认删除</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <form method="POST" action="{{ url_for('admindeposit.admindeposit') }}">
                <input type="hidden" name="action" value="delete">
                <input type="hidden" name="savingID" id="deleteSavingID">
                <div class="modal-body">
                    <p>确定要删除存款类型 "<span id="deleteDepositName" class="fw-bold"></span>" 吗？</p>
                    <p class="text-danger">此操作不可逆，请谨慎操作！</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-danger">确认删除</button>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script src="{{ url_for('static', filename='js/admin_main.js') }}"></script>
<script src="{{ url_for('static', filename='js/admin_deposit.js') }}"></script>
{% endblock %}